package com.iplatform.auth.config;

import com.iplatform.auth.service.impl.UserDetailServiceImpl;
import com.iplatform.commons.utils.Md5Util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * 密码校验器<br>
 * 2018.08.01
 *
 * @author LiLing
 */
@Configuration
public class PasswordEncoderConfig {
	private static final Logger LOG = LoggerFactory.getLogger(PasswordEncoderConfig.class);
    @Bean
    public PasswordEncoder passwordEncoder() {
        return new PasswordEncoder() {


			@Override
			public boolean matches(CharSequence rawPassword, String encodedPassword) {
				LOG.info("rawPassword:{}", rawPassword);
				LOG.info("encodedPassword:{}", encodedPassword);
				return rawPassword.equals(encodedPassword);
			}

	    	/**
			 * 针对前台密码进行加密，本来应该MD5之类加密，由于我们MD5在页面加密过，则这里直接返回
			 */
			@Override
			public String encode(CharSequence rawPassword) {
				return (String)rawPassword;
			}
		};
    }
}
